/*
* @Author: yyf
* @Create: 2018/5/10
* @description: 企业信息table
*/
<template>
    <div>
        <el-table :data="companyOpenSearchData">
            <el-table-column label="ID" prop="id" show-overflow-tooltip></el-table-column>
            <el-table-column label="企业名称" prop="fullName" show-overflow-tooltip>
                <template slot-scope="scope">
                    <el-button type="text" @click="getName(scope.row.id, scope.row.fullName)">{{scope.row.fullName}}</el-button>
                </template>
            </el-table-column>
            <el-table-column label="国际化名称" prop="intFullName" show-overflow-tooltip>
                <template slot-scope="scope">
                    <el-button type="text" @click="getName(scope.row.id, scope.row.intFullName)">{{scope.row.intFullName}}</el-button>
                </template>
            </el-table-column>
            <el-table-column label="企业简称" prop="shortName" show-overflow-tooltip>
                <template slot-scope="scope">
                    <el-button type="text" @click="getName(scope.row.id, scope.row.shortName)">{{scope.row.shortName}}</el-button>
                </template>
            </el-table-column>
            <el-table-column label="组织机构代码" prop="orgCode" show-overflow-tooltip>
                <!-- <template slot-scope="scope">
                    <el-button type="text">{{scope.row.orgCode}}</el-button>
                </template> -->
            </el-table-column>
            <el-table-column label="曾用名" prop="onceName" show-overflow-tooltip>
                <template slot-scope="scope">
                    <el-button type="text" @click="getName(scope.row.id, scope.row.onceName)">{{scope.row.onceName}}</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="align-center m-t-20">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page.sync="companySearch['pageParam.pageIndex']"
                :page-size="10"
                layout="prev, pager, next, jumper"
                :total="totalCount">
            </el-pagination>
        </div>
    </div>
</template>

<script lang="ts">
import Vue from 'vue';
import { Component, Prop } from 'vue-property-decorator';
import { CompanyOpenSearchVO } from '../../api/Interface';
import CompanyService from '../../service/common/index';
import { CompanySearch } from '../../service/common/interface';

interface MainCompanySearch {
    name: string;
    searchType: string;
    attribute: number;
}

@Component({
    components: {
    }
})
export default class CompanyInfoTable extends Vue {
    @Prop({default: {
        name: '',
        searchType: 'full_name',
        attribute: 1,
    }})
    public mainCompanySearch: MainCompanySearch;
    public companySearch: CompanySearch = {} as CompanySearch; // 根据条件搜索企业
    public companyOpenSearchData: Array<CompanyOpenSearchVO> = []; // 企业信息
    public pageSize: number = 0; // 页数
    public pageIndex: number = 1; // 当前页码
    public totalCount: number = 0; // 总页数

    // refs
    public $refs: {
    };

    // @Watch('companyDetailDialog')
    // public onChildChanged(val: boolean, oldVal: boolean) {
    //     if (val === true) {
    //         this.companySearch.name = '';
    //     } else {
    //         this.companyOpenSearchData = [];
    //     }
    // }

    // 声明周期钩子
    // public mounted() {
    // }

    // 获取企业信息
    public async getCompanyOpenSearchData() {
        this.companySearch = Object.assign({}, this.companySearch, this.mainCompanySearch);
        this.companySearch['pageParam.pageIndex'] = this.pageIndex;
        this.companySearch['pageParam.pageSize'] = 10;
        const res = await CompanyService.getCompanySearch(this.companySearch);
        if (res.resCode === '0') {
            this.companyOpenSearchData = res.data.resultData;
            this.totalCount = res.data.totalCount;
        }
    }
    public handleSizeChange(val: number) {
        this.pageSize = val;
    }
    public handleCurrentChange(val: number) {
        this.pageIndex = val;
        this.getCompanyOpenSearchData();
    }
    public getName(id: number, name: string) {
        this.companyOpenSearchData = [];
        this.$emit('getName', {id, name});
    }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>

</style>
